﻿@model ScheduleTaskModel
@{
	Layout = null;
	var returnUrl = (string)ViewBag.ReturnUrl;
    var canRead = ViewBag.CanRead == true;
    var canExecute = ViewBag.CanExecute == true;
}

<div class="d-inline-flex align-items-center py-1">
	<span class="badge mr-1@(Model.Enabled ? " badge-warning" : " badge-secondary")">@(Model.Enabled ? T("Common.Scheduled") : T("Common.Unscheduled"))</span>
	@if (Model.Enabled)
	{
		<span class="mr-1">@T("Common.Rule"): </span>
		<span class="text-muted">@(Model.CronDescription ?? Model.CronExpression)</span>
		if (Model.NextRun.HasValue)
		{
			<span> - @T("Admin.System.ScheduleTasks.NextRun"): </span>
			<span class="text-muted">@Model.NextRunPretty</span>
		}
	}
	else
	{
		<span class="mr-1">@T("Admin.System.ScheduleTasks.LastStart"): </span>
		<span class="text-muted">@(Model.LastHistoryEntry.FinishedOn.HasValue ? Model.LastHistoryEntry.FinishedOnPretty : T("Common.Never").Text)</span>
	}
	@if (canRead || canExecute)
	{
		<div class="dropdown btn-actions ml-3">
			<a class="btn btn-sm btn-secondary dropdown-toggle" data-toggle="dropdown" href="#">
				<i class="fa fa-cog"></i>
				<span>@T("Admin.Common.Actions")</span>
			</a>
			<div class="dropdown-menu">
                @if (canRead)
                {
				    <a class="dropdown-item" href="@Url.Action("Edit", new { id = Model.Id, returnUrl = returnUrl })">
					    @if (Model.Enabled)
                        {
						    <i class="fa fa-fw fa-edit"></i>
						    <span>@T("Admin.System.ScheduleTasks.EditTask")</span>
                        }
                        else
                        {
						    <i class="far fa-fw fa-clock"></i>
						    <span>@T("Admin.System.ScheduleTasks.ScheduleExecution")</span>
                        }
				    </a>
                }
                @if (canExecute)
                {
				    <a class="dropdown-item" href="@Model.ExecuteUrl" onclick='return confirm(@T("Admin.Common.AreYouSure").JsText);'>
					    <i class="fa fa-fw fa-play"></i>
					    <span>@T("Admin.System.ScheduleTasks.RunNow")</span>
				    </a>
                }
			</div>
		</div>
	}
</div>